package com.tienon.message.thread.task;



import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

import com.tienon.message.entity.Push_App;
import com.tienon.message.entity.Raw_msg_batch;
import com.tienon.message.mapper.Push_AppMapper;
import com.tienon.message.mapper.Raw_msg_batchMapper;

/**
 * app发送表子任务插入数据库操作
 * 实现事务管理
 * @author xiuye
 *
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Transactional
public class AppSendMsgDBSubTask {

	private static Logger log = Logger.getLogger(AppSendMsgDBSubTask.class);
	
	@Resource
	private Push_AppMapper appDao;
	@Resource
	private Raw_msg_batchMapper rawBatchDao;

	/**
	 * 插入app数据到数据库，和更新原始批处理表的相关数据
	 * 
	 * @param data
	 */
	public void addPushAppAndUpdateRawMsgBatch(Push_App data) {

		
	
		log.info("批次号："+data.getBatId()+"流水号："+ data.getSerial() +"内容:"+data.getMsg()+"正在插入Push_App数据表");
		/**
		 * 插入app发送表数据
		 */
		appDao.insertSelective(data);
		
		/**
		 * 更新原始表数据
		 * 这段代码的可能会包含数据处理
		 * 具体待定
		 */
		Raw_msg_batch rawData = new Raw_msg_batch();		
		rawData.setBatId(data.getBatId());
		rawData.setSerail(data.getSerial());
		rawData.setFilter(data.getFilter());		
		rawData.setSendNow(data.getSendNow());
		rawData.setSendTime(data.getSendTime());
		rawData.setMsgType(data.getMsgType());
		rawData.setMsg(data.getMsg());
		rawData.setSplitFlag(data.getSplitFlag());
		rawData.setSendWay(data.getSendWay());
		rawData.setBsnCd(data.getBsnCd());
		rawData.setSendTimes(data.getSendTimes());
		rawData.setOutChannle(data.getOutChannle());
		rawData.setPrior(data.getPrior());
		rawData.setReportFlag(data.getReportFlag());
		rawData.setOccDate(data.getOccDate());
		rawData.setLinkFlag(data.getLinkFlag());
		rawData.setState(4);
		rawData.setOccTime(data.getOccTime());
		rawData.setOutChanCustomId(data.getOutChanCustomId());
		log.info("批次号："+rawData.getBatId()+"流水号："+ rawData.getSerail() +"内容:"+rawData.getMsg()+"正在更新Raw_msg_batch的状态");
		rawBatchDao.updateByPrimaryKeySelective(rawData);

	}

}
